package com.example.gybicycle.service;

import java.util.Date;
import com.example.gybicycle.common.entity.Result;
import com.example.gybicycle.common.enums.NumType;
import com.example.gybicycle.common.sql.CrudService;
import com.example.gybicycle.common.util.NumberUtil;
import com.example.gybicycle.entity.BikeFailure;
import com.example.gybicycle.dao.BikeFailureDao;
import com.example.gybicycle.entity.MemberOrder;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class BikeFailureService extends CrudService<BikeFailureDao, BikeFailure> {
    @Override
    public BikeFailure get(Integer id) {
        BikeFailure table=super.get(id);
        return table;
    }

    public int  failureOrderNum(String orderId){
        BikeFailure failure=new BikeFailure();
        failure.setMemberOrderId(orderId);
        Integer num=dao.count(failure);
        return num==null?0:num;
    }

    /**
     * 确认故障
     * @param failure
     * @return
     */

    public Result<BikeFailure> confirmFailure(BikeFailure failure){
        if(failure.getFailureState()==null)
            return Result.fail("请确认是否故障");
        if(failure.getFailureState().equals(1)){
//            有故障
            BikeFailure failure2=dao.get(failure.getId());
            MemberOrder memberOrder=new MemberOrder();
            memberOrder.setId(failure2.getMemberOrderId());
            memberOrder.setEndTime(failure2.getFailureTime());
            memberOrder.setOrderState(2);
        }else if(failure.getFailureState().equals(2)){
//            无故障

        }
        return Result.success(failure);
    }

    @Override
    public int insert(BikeFailure entity) {
        entity.setId(NumberUtil.getNum(NumType.REPAIR));
        return super.insert(entity);
    }

    public List<BikeFailure> findList(BikeFailure entity){
        List<BikeFailure> list=super.findList(entity);
        return list;
    }


}